using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using System.CodeDom.Compiler;

using NBusiness.CodeDom;
using NBusiness.CodeDom.Compiler;

namespace NBusiness.ESharp.Compiler
{
    [Serializable]
	public class ESharpProvider : EntityProvider
	{
        [NonSerialized]
        private List<EntityBuildError> _errors = new List<EntityBuildError>();
        public List<EntityBuildError> Errors
        {
            get { return _errors; }
        }

		public override CompilerResults CompileAssemblyFromFiles(EntityCompilerParameters options, params EntityResourceFile[] files)
		{
			ESharpCompiler esc = new ESharpCompiler();
			return esc.CompileAssemblyFromFiles(options, files);
		}

		public override CompilerResults CompileAssemblyFromFamilies(EntityCompilerParameters options, EntityRoot root)
		{
			ESharpCompiler dc = new ESharpCompiler();
			return dc.CompileAssemblyFromFamilies(options, root);
		}

		public override EntityResourceFile[] GenerateFilesFromFamily(EntityCompilerParameters parameters, EntityRoot root)
		{
			ESharpGenerator dg = new ESharpGenerator();
			return dg.GenerateFilesFromFamily(parameters, root);
		}

		public override EntityRoot ParseCode(params string[] code)
		{
			ESharpParser p = new ESharpParser();
            p.ParserError += new EventHandler<EntityBuildErrorEventArgs>(Parser_ParserError);
			return p.ParseCode(code);
		}

		public override EntityRoot ParseFiles(params string[] files)
		{
			ESharpParser p = new ESharpParser();
            p.ParserError += new EventHandler<EntityBuildErrorEventArgs>(Parser_ParserError);
			return p.ParseFiles(files);
		}

		protected string CompilerName
		{
			get { return "ESharp"; }
		}

		public override string FileExtension
		{
			get { return "es"; }
		}

        void Parser_ParserError(object sender, EntityBuildErrorEventArgs e)
        {
            _errors.Add(e.Error);
        }

        [Obsolete]
        public override ICodeParser CreateParser()
        {
            return new ESharpParser();
        }

        [Obsolete]
        public override ICodeCompiler CreateCompiler()
        {
            return new ESharpCompiler();
        }

        [Obsolete]
        public override ICodeGenerator CreateGenerator()
        {
            return new ESharpGenerator();
        }
    }
}
